package com.kfm.storage.util;

/**
 * @author Aurora雪
 */

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 客户端类
 */
public class Cliend {
    /**
     * 远程服务器的端口号
     */
    private int remotePort;
    /**
     * 远程服务器的本地文件夹路径
     */
    private String localFolderPath;

    /**
     * 从配置文件中加载配置
     */
    public void loadConfig() {
        InputStream input = null;
        try {
            Properties prop = new Properties();
            input = null;

            try {
                // 读取配置文件
                input = getClass().getClassLoader().getResourceAsStream("cliend.properties");
                prop.load(input);


                remotePort = Integer.parseInt(prop.getProperty("remotePort"));
                localFolderPath = prop.getProperty("localFolderPath");

            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } catch (RuntimeException e) {
            throw new RuntimeException(e);
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    public int getRemotePort() {
        return remotePort;
    }

    public String getLocalFolderPath() {
        return localFolderPath;
    }
}
